<template>
    <div class="photoinfo-container">
        <h3>{{ imageInfo.title }}</h3>
        <p class="subtitle">
            <span>发表时间: {{ imageInfo.add_time | dateFormat }}</span>
            <span>点击次数：{{ imageInfo.click }}次</span>
        </p>
        <hr>
        <!-- 缩略图区域 -->
       <!-- <vue-preview :slides="slide1" @close="handleClose"></vue-preview> -->
       <img class="preview-img" height="100"  v-for="(item,index) in list" :key="item.src" :src="item.src" @click="$preview.open(index, list)">
        <!-- 图片内容区域 -->
        <div class="content" v-html="imageInfo.content"></div>

        <!-- 放置一个现成的评论子组件 -->
        <cmt-box :id="photoId"></cmt-box>
    </div>
</template>
<script>
//导入评论子组件
import comment from '../../subcomponents/comment.vue'
export default {
    data(){
        return{
            id: this.$route.params.id,
            imageInfo: {}, // 图片详情
            list: [], //缩略图数组
            photoId : 2
        }
    },
    created(){
        this.getPhotoInfo();
        this.getThumps();
    },
    methods:{
        getPhotoInfo(){
            //获取图片详情
            this.$http.get('/api/imageInfo').then((resp)=>{
                resp = resp.body
                if(resp.errno == 0){
                    this.imageInfo = resp.data[this.id-1]
                   
                }
            })
        },
        getThumps(){
            this.$http.get('/api/img').then((resp)=>{
                resp = resp.body
                if(resp.errno == 0){
                    
                    this.list = resp.data
                    var i = 0
                    //循环每个图片数据，补全宽和高
                    resp.data.forEach(item => {
                        i++;
                        item.alt = "picture" + i ;
                        item.w = 600;
                        item.h = 400;
                    });
                    this.list = resp.data
                }
            })
        },
        handleClose () {
        console.log('close event')
      }
    },
    components:{
       'cmt-box': comment
    }
}
</script>
<style lang="scss" scoped>
.photoinfo-container{
    padding: 4px;
    h3{
        color: #26a2ff;
        font-size: 15px;
        text-align: center;
        margin: 15px 0;
    }
    .subtitle{
        display: flex;
        justify-content: space-between;
    }
    .content{
        font-size: 13px;
        line-height: 30px;
    }
}
</style>